import 'package:cbec_app/components/base/base_function.dart';
import 'package:cbec_app/components/base/base_image.dart';
import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/base/image_text_item.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/components/common/dashed_line.dart';
import 'package:cbec_app/components/common/team_work_tag_item.dart';
import 'package:cbec_app/components/goods/goods_add_minus.dart';
import 'package:cbec_app/components/http/network.dart';
import 'package:cbec_app/components/popup/gifts_popup.dart';
import 'package:cbec_app/routes/routes.dart';
import 'package:cbec_app/utils/EventMgr.dart';
import 'package:cbec_app/utils/ThemeConfig.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:cbec_app/utils/logger.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../pages/main/controller/main_ctr.dart';

///领券弹窗
class ReceiveCouponPopup extends StatefulWidget {
  ///折扣信息
  final Map<String, dynamic> info;

  ///领券优惠券回调
  final Function(String couponId)? onReceiveCoupon;

  ///领取红包回调
  final Function(String redPacketId)? onReceiveRedPack;
  const ReceiveCouponPopup({super.key, required this.info, this.onReceiveCoupon, this.onReceiveRedPack});

  @override
  State<StatefulWidget> createState() {
    return _ReceiveCouponPopupState();
  }
}

class _ReceiveCouponPopupState extends State<ReceiveCouponPopup> {
  Map<String, dynamic> _info = {};
  @override
  void initState() {
    super.initState();
    _info = widget.info;
    print('_info ====== $_info');
    EventMgr.on(EventType.refreshDiscountPopup, (arg) {
      setState(() {
        _info = arg;
      });
    });
  }

  @override
  void dispose() {
    super.dispose();
    EventMgr.off(EventType.refreshDiscountPopup);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        height: MediaQuery.of(context).size.height * 0.8,
        decoration: const BoxDecoration(color: Colors.white, borderRadius: BorderRadius.only(topLeft: Radius.circular(8), topRight: Radius.circular(8))),
        child: Container(
          width: 375.w,
          padding: const EdgeInsets.only(top: 10, left: 10, right: 10),
          child: Stack(
            children: [
              SizedBox(
                width: 355.w,
                child: Column(
                  mainAxisSize: MainAxisSize.max,
                  children: [
                    Text(
                      '优惠',
                      style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700, color: Tools.fromHex('#333333')),
                    ),
                    Visibility(
                      visible: false,
                      child: Container(
                        width: 350.w,
                        margin: const EdgeInsets.only(top: 20),
                        decoration: BoxDecoration(border: Border.all(color: ThemeConfig.themeColor), borderRadius: const BorderRadius.all(Radius.circular(8))),
                        child: Column(
                          children: [
                            Container(
                              alignment: Alignment.center,
                              padding: const EdgeInsets.only(top: 20, bottom: 10),
                              child: goodsSalesPrice(_info['priceNow'].toString(), tips: '预估到手价', fontSize: 15, alignment: MainAxisAlignment.center),
                            ),
                            Container(
                              width: 300,
                              height: 1,
                              color: ThemeConfig.themeColor,
                            ),
                            Container(
                              margin: const EdgeInsets.only(top: 10),
                              child: Text(
                                '现在购买，享受以下优惠',
                                style: setTextStyle(14, FontWeight.normal, ThemeConfig.sectionTextColor),
                              ),
                            ),
                            const SizedBox(
                              height: 20,
                            ),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                discountBox(_info['price'].toString(), '原价'),
                                _info['priceSpecialDiscount'] != null && _info['priceSpecialDiscount'] != 0
                                    ? Container(
                                        width: 10,
                                        height: 1,
                                        margin: EdgeInsets.only(left: 5, right: 5),
                                        color: ThemeConfig.themeColor,
                                      )
                                    : emptyWidget(),
                                _info['priceSpecialDiscount'] != null && _info['priceSpecialDiscount'] != 0 ? discountBox(_info['priceSpecialDiscount'].toString(), '促销') : emptyWidget()
                              ],
                            ),
                            const SizedBox(
                              height: 20,
                            )
                          ],
                        ),
                      ),
                    ),
                    Expanded(
                      child: SingleChildScrollView(
                        child: Column(
                          children: [
                            //促销
                            Column(crossAxisAlignment: CrossAxisAlignment.start, children: createSalesList()),
                            //优惠券
                            Column(crossAxisAlignment: CrossAxisAlignment.start, children: createCouponList()),
                            //赠品
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: createSendList(),
                            ),
                            //加价购
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: createAddPriceList(),
                            ),
                            //红包
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: createRedPackList(),
                            ),
                            //返红包
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: createReturnRedPackList(),
                            ),
                            //返券
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: createReturnCouponList(),
                            ),
                          ],
                        ),
                      ),
                    )
                  ],
                ),
              ),
              Positioned(
                  top: 0,
                  right: 0,
                  child: BaseInteractive(
                    childWidget: Icon(Icons.close, color: Tools.fromHex('#333333')),
                    onClick: () {
                      Get.back();
                    },
                  ))
            ],
          ),
        ));
  }

  ///优惠标题
  Widget preferentialTitle(String title) {
    return Container(
      margin: const EdgeInsets.only(bottom: 10),
      child: Text(
        title,
        style: setTextStyle(16, FontWeight.normal, ThemeConfig.mainTextColor),
      ),
    );
  }

  ///通用item
  Widget commonItem(Widget text, Widget content) {
    return Container(
      width: 348.w,
      height: 100,
      margin: const EdgeInsets.only(bottom: 10),
      decoration: BoxDecoration(border: Border.all(color: ThemeConfig.themeColor), borderRadius: const BorderRadius.all(Radius.circular(20))),
      child: Row(
        mainAxisSize: MainAxisSize.max,
        children: [
          Container(
            width: 80.w,
            alignment: Alignment.center,
            child: text,
          ),
          const SizedBox(
            width: 1,
            child: DashedLind(
              axis: Axis.vertical,
              count: 20,
              color: ThemeConfig.themeColor,
            ),
          ),
          Container(
            width: 255.w,
            child: content,
          )
        ],
      ),
    );
  }

  ///促销item
  Widget salesItem(Map<String, dynamic> item) {
    return commonItem(
        Text(
          '满减',
          style: setTextStyle(16, FontWeight.bold, ThemeConfig.themeColor),
        ),
        BaseInteractive(
          childWidget: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Expanded(
                child: Container(
                  // width: 240.w,
                  margin: const EdgeInsets.only(left: 10),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        item['activityContent'] ?? '',
                        style: setTextStyle(14, FontWeight.normal, ThemeConfig.mainTextColor),
                      ),
                      const SizedBox(
                        height: 10,
                      ),
                      Text(
                        item['activityTime'] ?? '',
                        style: setTextStyle(14, FontWeight.w300, ThemeConfig.subTextColor),
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                      )
                    ],
                  ),
                ),
              ),
              const Icon(
                Icons.navigate_next,
                color: ThemeConfig.subTextColor,
              )
            ],
          ),
          onClick: () {},
        ));
  }

  ///生成促销列表
  List<Widget> createSalesList() {
    List<Widget> arr = [];
    if (_info['goodsActivityInfo'] == null || (_info['goodsActivityInfo'] as List).isEmpty) {
      return arr;
    }
    arr.add(preferentialTitle('促销'));
    for (var item in _info['goodsActivityInfo']) {
      arr.add(salesItem(item));
    }
    return arr;
  }

  ///优惠券item
  Widget couponItem(Map<String, dynamic> item) {
    return commonItem(
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              item['type'] ?? '',
              style: setTextStyle(16, FontWeight.bold, ThemeConfig.themeColor),
            ),
          ],
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Expanded(
              child: Container(
                margin: const EdgeInsets.only(left: 10),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      item['name'] ?? '',
                      style: setTextStyle(14, FontWeight.normal, ThemeConfig.mainTextColor),
                    ),
                    const SizedBox(
                      height: 5,
                    ),
                    Text(
                      item['goodsType'] ?? '',
                      style: setTextStyle(14, FontWeight.normal, ThemeConfig.mainTextColor),
                    ),
                    const SizedBox(
                      height: 5,
                    ),
                    Text(
                      // '有效期：${item['validityType'] == 1 ? '永久有效' : '${item['validityStartTime']} - ${item['validityEndTime']}'}',
                      '${item['validityStartTime']} - ${item['validityEndTime']}',
                      style: setTextStyle(14, FontWeight.w300, ThemeConfig.subTextColor),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    )
                  ],
                ),
              ),
            ),
            BaseInteractive(
              childWidget: Container(
                padding: const EdgeInsets.only(left: 10, right: 10, bottom: 5, top: 5),
                decoration: BoxDecoration(border: Border.all(color: item['hasGet'] == 0 ? ThemeConfig.themeColor : ThemeConfig.subTextColor), borderRadius: const BorderRadius.all(Radius.circular(30))),
                child: Text(
                  item['hasGet'] == 0 ? '立即领取' : '已领取',
                  style: setTextStyle(12, FontWeight.normal, item['hasGet'] == 0 ? ThemeConfig.themeColor : ThemeConfig.sectionTextColor),
                ),
              ),
              onClick: () {
                if (widget.onReceiveCoupon != null) {
                  widget.onReceiveCoupon!(item['couponId']);
                }
              },
            )
          ],
        ));
  }

  ///生成优惠券列表
  List<Widget> createCouponList() {
    List<Widget> arr = [];
    if (_info['couponList'] == null || (_info['couponList'] as List).isEmpty) {
      return arr;
    }
    arr.add(preferentialTitle('优惠券'));
    for (var item in _info['couponList']) {
      arr.add(couponItem(item));
    }
    return arr;
  }

  ///赠品item
  Widget sendItem() {
    return commonItem(
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              _info['sendNumber'].toString(),
              style: setTextStyle(16, FontWeight.bold, ThemeConfig.themeColor),
            ),
            Text(
              '件赠品',
              style: setTextStyle(14, FontWeight.normal, ThemeConfig.themeColor),
            ),
          ],
        ),
        BaseInteractive(
          childWidget: Row(
            children: [
              Container(
                width: 240.w,
                margin: const EdgeInsets.only(left: 10),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      '下单享赠品(赠完即止)',
                      style: setTextStyle(14, FontWeight.normal, ThemeConfig.mainTextColor),
                    ),
                    const SizedBox(
                      height: 5,
                    ),
                    Row(
                      children: (_info['sendGoodsList'] as List)
                          .map((item) => Container(
                                margin: EdgeInsets.only(right: 10),
                                child: BaseImage(
                                  url: item['img'] ?? 'https://indoorbuydev.oss-cn-hangzhou.aliyuncs.com/bbc-channel-web/material/20240524/fbd491ed-3a0d-4db0-a571-d6ef6e164e65-微信图片_20240524211415.png"',
                                  width: 32.w,
                                  height: 32.w,
                                ),
                              ))
                          .toList(),
                    )
                  ],
                ),
              ),
              const Icon(
                Icons.navigate_next,
                color: ThemeConfig.subTextColor,
              )
            ],
          ),
          onClick: () {
            showGiftsPopup(_info['sendGoodsList']);
          },
        ));
  }

  ///生成赠品列表
  List<Widget> createSendList() {
    List<Widget> arr = [];
    if (_info['sendGoodsList'] == null || (_info['sendGoodsList'] as List).isEmpty) {
      return arr;
    }
    arr.add(preferentialTitle('赠品'));
    arr.add(sendItem());
    return arr;
  }

  ///加价购item
  Widget addPriceItem() {
    return commonItem(
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              '加价购',
              style: setTextStyle(16, FontWeight.bold, ThemeConfig.themeColor),
            ),
          ],
        ),
        BaseInteractive(
          childWidget: Row(
            children: [
              Expanded(
                child: Container(
                  margin: const EdgeInsets.only(left: 10),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        '加N元可换够其他商品',
                        style: setTextStyle(14, FontWeight.normal, ThemeConfig.mainTextColor),
                      ),
                      const SizedBox(
                        height: 5,
                      ),
                      Row(
                        children: (_info['sendGoodsList'] as List)
                            .map((item) => Container(
                                  margin: EdgeInsets.only(right: 10),
                                  child: BaseImage(
                                    url: item['img'] ?? 'https://indoorbuydev.oss-cn-hangzhou.aliyuncs.com/bbc-channel-web/material/20240524/fbd491ed-3a0d-4db0-a571-d6ef6e164e65-微信图片_20240524211415.png"',
                                    width: 32.w,
                                    height: 32.w,
                                  ),
                                ))
                            .toList(),
                      )
                    ],
                  ),
                ),
              ),
              const Icon(
                Icons.navigate_next,
                color: ThemeConfig.subTextColor,
              )
            ],
          ),
          onClick: () {},
        ));
  }

  ///生成加价购列表
  List<Widget> createAddPriceList() {
    List<Widget> arr = [];
    if (_info['plusActivity'] == null || (_info['plusActivity'] as List).isEmpty) {
      return arr;
    }
    arr.add(preferentialTitle('加价购'));
    arr.add(addPriceItem());
    return arr;
  }

  ///红包item
  Widget redPackItem(Map<String, dynamic> item) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
            decoration: const BoxDecoration(
              color: Colors.transparent,
              image: DecorationImage(
                image: AssetImage("assets/images/redpack_bg.png"),
                fit: BoxFit.cover,
              ),
            ),
            // constraints: BoxConstraints(maxHeight: 200.w),
            margin: EdgeInsets.only(top: 10.w),
            padding: EdgeInsets.only(top: 5.w, bottom: 5.w),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              mainAxisSize: MainAxisSize.max,
              children: [
                Row(
                  children: [
                    //左
                    Container(
                      width: 80.w,
                      height: 80.h,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [Text("￥${Tools.formatNumber(item['price'])}", style: const TextStyle(fontSize: 22, fontWeight: FontWeight.w700, color: Color.fromRGBO(210, 152, 64, 1))), Text(item['content'], style: const TextStyle(fontSize: 10, fontWeight: FontWeight.w300, color: Color.fromRGBO(210, 152, 64, 1)))],
                      ),
                    ),
                    //中
                    Container(
                      height: 80.h,
                      width: 160.w,
                      margin: EdgeInsets.fromLTRB(10.w, 0.w, 20.w, 0.w),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(item['redPacketName'], style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w700, color: Color.fromRGBO(251, 241, 216, 1))),
                          Text(item['goodsType'] ?? '未知', style: const TextStyle(fontSize: 10, fontWeight: FontWeight.w300, color: Color.fromRGBO(251, 241, 216, 1))),
                          Text(item['useDate'] ?? '', style: const TextStyle(fontSize: 10, fontWeight: FontWeight.w300, color: Color.fromRGBO(251, 241, 216, 1))),
                        ],
                      ),
                    ),
                  ],
                ),

                //右【按钮】

                Expanded(
                  child: Container(
                    margin: EdgeInsets.only(right: 8.w),
                    child: Column(
                      children: [
                        SizedBox(
                          height: 30,
                          child: TextButton(
                            style: item['hasGet'] == 0
                                ? ButtonStyle(
                                    backgroundColor: WidgetStateProperty.all(Tools.fromHex("#F83F2D")),
                                    side: WidgetStateProperty.all(const BorderSide(color: Color.fromRGBO(251, 241, 216, 1), width: 1.0)),
                                  )
                                : ButtonStyle(
                                    backgroundColor: WidgetStateProperty.all(const Color.fromRGBO(204, 204, 204, 1)),
                                  ),
                            onPressed: () {
                              if (item['hasGet'] != 0) {
                                return;
                              }
                              if (widget.onReceiveRedPack != null) {
                                widget.onReceiveRedPack!(item['redPacketId']);
                              }
                            },
                            child: Text(
                              item['hasGet'] == 0 ? '立即领取' : '已领取',
                              style: item['hasGet'] == 0 ? const TextStyle(fontSize: 10, fontWeight: FontWeight.w300, color: Colors.white) : const TextStyle(fontSize: 10, fontWeight: FontWeight.w300, color: Color.fromRGBO(251, 241, 216, 1)),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                )
              ],
            )),
      ],
    );

    // commonItem(
    //   Column(
    //     mainAxisAlignment: MainAxisAlignment.center,
    //     children: [
    //       Text(
    //         '￥${item['price'].toString()}',
    //         style: setTextStyle(16, FontWeight.bold, ThemeConfig.themeColor),
    //       ),
    //       Text(
    //         item['content'].toString(),
    //         style: setTextStyle(12, FontWeight.normal, ThemeConfig.themeColor),
    //       ),
    //     ],
    //   ),
    //   Row(
    //     mainAxisAlignment: MainAxisAlignment.spaceBetween,
    //     children: [
    //       Expanded(
    //         child: Container(
    //           margin: const EdgeInsets.only(left: 10),
    //           child: Column(
    //             mainAxisAlignment: MainAxisAlignment.center,
    //             crossAxisAlignment: CrossAxisAlignment.start,
    //             children: [
    //               Text(
    //                 item['redPacketName'] ?? '',
    //                 style: setTextStyle(14, FontWeight.normal, ThemeConfig.mainTextColor),
    //               ),
    //               const SizedBox(
    //                 height: 5,
    //               ),
    //               Text(
    //                 item['content'] ?? '',
    //                 style: setTextStyle(14, FontWeight.normal, ThemeConfig.mainTextColor),
    //               ),
    //               const SizedBox(
    //                 height: 5,
    //               ),
    //               Text(
    //                 '有效期：${item['validityType'] == 1 ? '永久有效' : '${item['startTime']} - ${item['endTime']}'}',
    //                 style: setTextStyle(14, FontWeight.w300, ThemeConfig.subTextColor),
    //                 maxLines: 1,
    //                 overflow: TextOverflow.ellipsis,
    //               )
    //             ],
    //           ),
    //         ),
    //       ),
    //       BaseInteractive(
    //         childWidget: Container(
    //           padding: const EdgeInsets.only(left: 10, right: 10, bottom: 5, top: 5),
    //           decoration: BoxDecoration(border: Border.all(color: item['hasGet'] == 0 ? ThemeConfig.themeColor : ThemeConfig.subTextColor), borderRadius: const BorderRadius.all(Radius.circular(30))),
    //           child: Text(
    //             item['hasGet'] == 0 ? '立即领取' : '已领取',
    //             style: setTextStyle(12, FontWeight.normal, item['hasGet'] == 0 ? ThemeConfig.themeColor : ThemeConfig.sectionTextColor),
    //           ),
    //         ),
    //         onClick: () {
    //           if (widget.onReceiveRedPack != null) {
    //             widget.onReceiveRedPack!(item['redPacketId']);
    //           }
    //         },
    //       )
    //     ],
    //   ));
  }

  ///生成红包列表
  List<Widget> createRedPackList() {
    List<Widget> arr = [];
    if (_info['redPackList'] == null || (_info['redPackList'] as List).isEmpty) {
      return arr;
    }
    arr.add(preferentialTitle('红包'));
    for (var item in _info['redPackList']) {
      arr.add(redPackItem(item));
    }
    return arr;
  }

  ///购物返红包item
  Widget returnRedPackItem(Map<String, dynamic> item) {
    return commonItem(
        Text(
          '返红包',
          style: setTextStyle(16, FontWeight.bold, ThemeConfig.themeColor),
        ),
        BaseInteractive(
          childWidget: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Container(
                width: 240.w,
                margin: const EdgeInsets.only(left: 10),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      item['content'] ?? '',
                      style: setTextStyle(14, FontWeight.normal, ThemeConfig.mainTextColor),
                    ),
                    const SizedBox(
                      height: 5,
                    ),
                    Text(
                      '￥${item['price'].toString()}',
                      style: setTextStyle(14, FontWeight.w300, ThemeConfig.subTextColor),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    ),
                    const SizedBox(
                      height: 5,
                    ),
                    Text(
                      '有效期：${item['validityType'] == 1 ? '永久有效' : '${item['startTime']} - ${item['endTime']}'}',
                      style: setTextStyle(14, FontWeight.w300, ThemeConfig.subTextColor),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    )
                  ],
                ),
              ),
              const Icon(
                Icons.navigate_next,
                color: ThemeConfig.subTextColor,
              )
            ],
          ),
          onClick: () {},
        ));
  }

  ///生成返红包列表
  List<Widget> createReturnRedPackList() {
    List<Widget> arr = [];
    if (_info['returnRedPackList'] == null || (_info['returnRedPackList'] as List).isEmpty) {
      return arr;
    }
    arr.add(preferentialTitle('返红包'));
    for (var item in _info['returnRedPackList']) {
      arr.add(returnRedPackItem(item));
    }
    return arr;
  }

  ///购物返优惠券item
  Widget returnCouponItem(Map<String, dynamic> item) {
    return commonItem(
        Text(
          '返券',
          style: setTextStyle(16, FontWeight.bold, ThemeConfig.themeColor),
        ),
        BaseInteractive(
          childWidget: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Container(
                width: 240.w,
                margin: const EdgeInsets.only(left: 10),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      item['name'] ?? '',
                      style: setTextStyle(14, FontWeight.normal, ThemeConfig.mainTextColor),
                    ),
                    const SizedBox(
                      height: 5,
                    ),
                    Text(
                      item['content'] ?? '',
                      style: setTextStyle(14, FontWeight.normal, ThemeConfig.mainTextColor),
                    ),
                    const SizedBox(
                      height: 5,
                    ),
                    Text(
                      '有效期：${item['validityType'] == 1 ? '永久有效' : '${item['validityStartTime']} - ${item['validityEndTime']}'}',
                      style: setTextStyle(14, FontWeight.w300, ThemeConfig.subTextColor),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    )
                  ],
                ),
              ),
              const Icon(
                Icons.navigate_next,
                color: ThemeConfig.subTextColor,
              )
            ],
          ),
          onClick: () {},
        ));
  }

  ///生成返优惠券列表
  List<Widget> createReturnCouponList() {
    List<Widget> arr = [];
    if (_info['returnCouponList'] == null || (_info['returnCouponList'] as List).isEmpty) {
      return arr;
    }
    arr.add(preferentialTitle('返券'));
    for (var item in _info['returnCouponList']) {
      arr.add(returnCouponItem(item));
    }
    return arr;
  }

  ///商品原价及优惠容器
  Widget discountBox(String price, String tips) {
    return Container(
      width: 80,
      decoration: BoxDecoration(border: Border.all(color: ThemeConfig.themeColor), borderRadius: BorderRadius.all(Radius.circular(5))),
      child: Column(
        children: [
          Padding(
            padding: EdgeInsets.only(top: 5, bottom: 5),
            child: Column(
              children: [
                Text(
                  '￥$price',
                  style: setTextStyle(16, FontWeight.w600, ThemeConfig.themeColor),
                ),
                Text(
                  tips,
                  style: setTextStyle(14, FontWeight.normal, ThemeConfig.themeColor),
                ),
              ],
            ),
          ),
          // Container(
          //   height: 1,
          //   color: ThemeConfig.themeColor,
          // ),
          // Padding(
          //   padding: EdgeInsets.only(top: 5, bottom: 5),
          //   child: Text(
          //     '满300-50',
          //     style: setTextStyle(12, FontWeight.w300, ThemeConfig.themeColor),
          //   ),
          // ),
          // const SizedBox(
          //   height: 1,
          //   child: DashedLind(
          //     axis: Axis.horizontal,
          //     color: ThemeConfig.themeColor,
          //     count: 30,
          //   ),
          // ),
          // Padding(
          //   padding: EdgeInsets.only(top: 5, bottom: 5),
          //   child: Column(
          //     children: [
          //       Text(
          //         '权益卡立减',
          //         style:
          //             setTextStyle(14, FontWeight.w300, ThemeConfig.themeColor),
          //       ),
          //       Text(
          //         '￥20',
          //         style:
          //             setTextStyle(12, FontWeight.w300, ThemeConfig.themeColor),
          //       )
          //     ],
          //   ),
          // )
        ],
      ),
    );
  }
}

///打开领券弹框
///info 折扣信息
///onReceiveCoupon 领取优惠券回调
void showReceiveCouponPopup({required Map<String, dynamic> info, Function(String couponId)? onReceiveCoupon, Function(String redPacketId)? onReceiveRedPack}) {
  showCupertinoModalPopup(
    context: Get.context!,
    builder: (context) {
      return StatefulBuilder(
        builder: (context, setState) {
          return ReceiveCouponPopup(
            info: info,
            onReceiveCoupon: onReceiveCoupon,
            onReceiveRedPack: onReceiveRedPack,
          );
        },
      );
    },
  );
}
